package com.icehand.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 过滤器
 * 不管是属于哪个Servlet只要复合过滤器的过滤规则，过滤器都会拦截
 * 自定义多个过滤器，执行的先后顺序跟类名排序有关
 * Created by icehand on 2017/5/12.
 */
@WebFilter(filterName = "myFilter" , urlPatterns = "/user/*")
public class MyFilter implements Filter {
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("Init filter");
	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
		System.out.println("do filter.......");
		//do something
		filterChain.doFilter(servletRequest,servletResponse);
	}

	@Override
	public void destroy() {
		System.out.println("destroy filter");
	}
}
